package com.yan.practice;

import java.lang.reflect.Constructor;
import java.util.Scanner;

/**
 * @author taoge
 * @Date 2024/8/15 19:47
 * @Description
 */
public class Practice1 {
    public static void main(String[] args) throws Exception {
        Scanner input = new Scanner(System.in);
        System.out.println("录入学生信息（姓名:年龄:成绩）");
        String stu = input.nextLine();
        String[] split = stu.split(":");
        Class<Student> c = Student.class;
        Constructor<Student> cons = c.getConstructor(String.class, Integer.class, Float.class);
        String name = split[0];
        Integer age = Integer.parseInt(split[1]);
        float grade = Float.parseFloat(split[2]);
        Student student = cons.newInstance("name", age, grade);
        System.out.println(student);
    }
}


 class Student {
    private String name;
    private Integer age;
    private Float grade;

    public Student() {

    }

    public Student(String name, Integer age, Float grade) {
        this.name = name;
        this.age = age;
        this.grade = grade;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Float getGrade() {
        return grade;
    }

    public void setGrade(Float grade) {
        this.grade = grade;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (name != null ? !name.equals(student.name) : student.name != null) return false;
        if (age != null ? !age.equals(student.age) : student.age != null) return false;
        return grade != null ? grade.equals(student.grade) : student.grade == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (age != null ? age.hashCode() : 0);
        result = 31 * result + (grade != null ? grade.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", grade=" + grade +
                '}';
    }
}

